using FairyGUI;
using FairyGUI.Utils;
using UnityEngine;
using System.IO;
using System.Collections.Generic;

namespace UIPack
{
    public partial class ComStage : GComponent
    {
        private static ComStage ins;
        public static ComStage Instance
        {
            get
            {
                if (ins == null)
                {
                    ins = CreateInstance();
                    ins.Init();
                }

                return ins;
            }
        }

        private Stack<GComponent> StackContent = new Stack<GComponent>();
        private GComponent CurrActiveCom = null;
        public void Init() {
            MakeFullScreen();

            AnimLoading.visible = false;
        }

        /// <summary>
        /// 添加到内容容器
        /// </summary>
        /// <param name="com"></param>
        public void Add2Content(GComponent com, bool isInStack = true) {
            if (isInStack) {
                StackContent.Push(com);
            }
            if (CurrActiveCom != null) {
                Content.RemoveChild(CurrActiveCom);
            }
            CurrActiveCom = com;
            Content.AddChild(com);
        }

        /// <summary>
        /// 移除Content当前的UI
        /// </summary>
        public void RemoveFromContent() {
            if (CurrActiveCom != null) {//如果有 直接删除
                Content.RemoveChild(CurrActiveCom);
            }

            if (StackContent.Count > 0 && CurrActiveCom == StackContent.Peek()) { //在 stack 中 就弹出
                StackContent.Pop();
            }

            if (StackContent.Count > 0) { //如果stack里面还有 就添加它
                CurrActiveCom = StackContent.Peek();
                Content.AddChild(CurrActiveCom);
            }
            else {
                CurrActiveCom = null;
            }
        }

        #region UI事件
        #endregion
    }
}